<?php 
	// include classes, functions and global variables and constants definition
	// it also initialise the page variables
	require_once("resources/php/init.php");								
?><!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title><?php echo Content::TEMPLATE_META_TITLE; ?></title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link href="<?php echo MOBILE; ?>/resources/styles/styles.css" rel="stylesheet" type="text/css" />
		<?php if( ((int)$_GET['image'] != 0) && ($user->isLogged)) { ?>
		<?php if( $isiOS ) { ?>
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
		<?php } ?>
		<script type="text/javascript">
			function emailDepositForm(){

		<?php if( !$isiOS ) { ?>

				var daReferrer = document.referrer;
				var email = "<?php echo REPOSITORY_MAIL; ?>";
				var subject = "<?php echo (int)$_GET['image']; ?>";
				var body_message = Array();
				body_message.push("#");
				body_message.push("DO NOT EDIT! -- PLEASE ATTACH YOUR MEDIA FILE BEFORE SENDING");
				body_message.push("original_id: <?php echo (int)$_GET['image']; ?>");
				body_message.push("userid: <?php echo $user->user_id; ?>");
				body_message.push("title: "+document.getElementById("title").value);
				body_message.push("abstract: "+document.getElementById("abstract").value);
				body_message.push("###############################################");
				body_message.push("PLEASE DO NOT EDIT THIS EMAIL AS IT MAY RESULT IN YOUR SUBMISSION BEING DISCARDED");

				var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+encodeURIComponent(body_message.join("****"));
				// With jQuery I would trigger a click. but that would be 32kb extra on the filesize
				//If you know of a truly cross-browser way to trigger a click feel free to insert it here.
				win = window.open(mailto_link,'emailWindow');
				if (win && win.open &&!win.closed) win.close();
				
				location.href = window.location.href.replace("#","") + "&sent=1";
				
				return false;
				
		<?php } else { ?>		

				return true;

		<?php } ?>				
			}
			
			function delayer() {
				window.location = window.location.href + "&sent=1";
			}
			
			<?php if( $isiOS ) { ?>
			
			function updateLink() {
				var daReferrer = document.referrer;
				var email = "<?php echo REPOSITORY_MAIL; ?>";
				var subject = "<?php echo (int)$_GET['image']; ?>";
				var body_message = Array();
				body_message.push("#");
				body_message.push("DO NOT EDIT! -- PLEASE ATTACH YOUR MEDIA FILE BEFORE SENDING");
				body_message.push("original_id: <?php echo (int)$_GET['image']; ?>");
				body_message.push("userid: <?php echo $user->user_id; ?>");
				body_message.push("title: "+$("#title").val());
				body_message.push("abstract: "+$("#abstract").val());
				body_message.push("###############################################");
				body_message.push("PLEASE DO NOT EDIT THIS EMAIL AS IT MAY RESULT IN YOUR SUBMISSION BEING DISCARDED");

				var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+encodeURIComponent(body_message.join("****"));
				
				$("#sendMail").attr("href", mailto_link);
			}
			
			jQuery(document).ready(function($) {
			
				updateLink();
				$("#sendMail").after("<p><?php echo Content::IOS_FAIL; ?></p>");
			
				$("#title").keyup(function(){
					updateLink();
				});
				$("#abstract").keyup(function(){
					updateLink();
				});
			});
			
			<?php } ?>
			
		</script>
		<?php } ?>
	</head>
	<body>
		<div id="wrap">
				<div id="header">
					<h2><?php echo Content::TEMPLATE_TITLE; ?></h2>
				</div>
				<a id="top"></a>
				<div id="menu">
					<ul class="menu">
						<?php echo $main_menu; ?>		
					</ul>					
				</div>
			<div id="content">
				<?php echo $breadcrumb; ?>		
				<?php echo $content; ?>		
				<p class="top"><a href="#top"><?php echo Content::TEMPLATE_BACKTOTOP; ?></a></p>
			</div>
			<div id="footer">
				<ul class="menu">
					<li><a title="<?php echo Content::TEMPLATE_DESKTOP; ?>" href="<?php echo HTTP;?>?force_desktop=1"><?php echo Content::TEMPLATE_SWITCH_DESKTOP; ?></a> |</li>
					<li><a title="<?php echo Content::TEMPLATE_TERMS; ?>" <?php if($page == "conditions-of-use") {echo 'class="selected"';} else {echo 'href="conditions-of-use'; if($user->isLogged) { echo "?".htmlspecialchars(SID); } echo '"'; } ?> >Conditions of use</a> |</li>
					<li><a title="<?php echo Content::TEMPLATE_FEEDBACK; ?>" href="mailto:docenquiry@soas.ac.uk?subject=<?php echo Content::TEMPLATE_FEEDBACK_SUB; ?>&body=<?php echo Content::TEMPLATE_FEEDBACK_BODY; ?>"><?php echo Content::TEMPLATE_FEEDBACK; ?></a></li>
				</ul>
			</div>
		</div>
	</body>
</html>